import {getIp} from './util/osInfo.js'
import express from 'express'
import mapRouter from './routers/mapRouter.js'
import peopleRouter from './routers/peopleRouter.js'
import robotsRouter from './routers/robotsRouter.js'
import weaponRouter from './routers/weaponRouter.js'
import uploadRouter from './routers/uploadRouter.js'
import cors from 'cors'

const app = express()

const serverIp = getIp()
console.log(`the server ip is : ${serverIp}`);
const serverPort = 9600;
app.use((req,res,next)=>{
  res.serverIp = serverIp
  res.serverPort = serverPort
  res.res_baseUrl = `http://${serverIp}:${serverPort}`
  next()
})

app.use('/assets', express.static('./assets'))
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.listen(serverPort)

app.use('/map', mapRouter)
app.use('/people', peopleRouter)
app.use('/robots', robotsRouter)
app.use('/weapon', weaponRouter)
app.use('/upload', uploadRouter)
